/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

public class ChartLegend extends Canvas {
	public void paint(Graphics g) {
		super.paint(g);
		// set the size of the accompanying rectangle.
		int vstep = getHeight() / chart.getData().length;
		int hstep = 11;
		String[] names = chart.getNames();
		for (int i = 0; i < chart.getData().length; i++) {
			g.setColor(chart.getElementColor(i));
			g.drawRect(0, vstep * i, hstep, vstep);
			g.setColor(Color.black);
			if (names != null)
				if (names[i] != null)
					g.drawString(names[i], 13, vstep * i + vstep / 2);
				else
					g.drawString(Integer.toString(chart.getData()[i]), 13,
							vstep * i + vstep / 2);
		}
	}

	public void setChart(IChart c) {
		chart = c;
		repaint();
	}

	private IChart chart;
}
